﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Citi.HeadCount.Domain;
using System.ComponentModel.DataAnnotations;

namespace Citi.HeadCount.WebUI.Models
{
    public class RuleViewModel
    {
        public int RuleResultId { get; set; }
        [Display(Name="Column: ")]
        public int Type { get; set; }
        [Display(Name = "Description: ")]
        public string TypeDescription { get; set; }
        [Display(Name = "Level: ")]
        public int Level { get; set; }
        [Display(Name = "Value: ")]
        public string Value { get; set; }
        public int Id { get; set; }

        public static RuleViewModel CreateModel(Rule domain)
        {
            return new RuleViewModel
            {
                Level = domain.Level,
                RuleResultId = domain.RuleResultId,
                Value = domain.Value,
                Type = (int)domain.Type,
                TypeDescription = domain.Type.GetDescription(),
                Id = domain.Id
            };
        }

        public static IEnumerable<RuleViewModel> CreateModel(IEnumerable<Rule> domains)
        {
            return domains.Select(CreateModel).ToList();
        }

        public static Rule CreateDomain(RuleViewModel model)
        {
            return new Rule
            {
                Level = model.Level,
                RuleResultId = model.RuleResultId,
                Value = model.Value,
                Type = (RuleType) model.Type,
                Id = model.Id,
                LastUpdate = DateTime.Now
            };
        }

        public static IEnumerable<Rule> CreateDomain(IEnumerable<RuleViewModel> domains)
        {
            return domains.Select(CreateDomain).ToList();
        }
    }
}